#include <fstream>
#include <sstream>
#include "MTDriver.hh"
#include "Scanner.h"

namespace MathematicaTranslator 
{
	MTDriver::MTDriver()
		: traceScanning(false), traceParsing(false)
	{
	}
	MTDriver::~MTDriver()
	{
	}

	int MTDriver::parse_stream(std::istream& in,
		      const std::string& sname = "stream input")
	{
		this->streamname = sname;

		Scanner scanner(&in);
		scanner.set_debug(traceScanning);
		this->scanner = &scanner;

		Parser parser(*this);
		parser.set_debug_level(traceParsing);
		return (parser.parse() == 0);

	}

	int MTDriver::parse_file(const std::string &filename)
	{
		std::ifstream in(filename.c_str());
		if (!in.good()) return false;
		return parse_stream(in, filename);
	}

	int MTDriver::parse_string(const std::string &input, const std::string& sname)
	{
		std::istringstream iss(input);
		return parse_stream(iss, sname);
	}

	void MTDriver::error(const class location& l,
		const std::string& m)
	{
		std::cerr << l << ": " << m << std::endl;
	}

	void MTDriver::error(const std::string& m)
	{
		std::cerr << m << std::endl;
	}

}